<template>
  <div class="zhibiaocontainer" v-loading="isloading">
    <div class="over-header">
      <div class="header"><i class="el-icon-d-arrow-right"></i>按条件筛选</div>
      <div class="search">
        <div class="zahungtai">
          <span style="width: 190px"
            ><i class="icon iconfont el-icon-s-promotion"></i>是否上报：</span
          >
          <el-radio-group
            v-model="listquery.isUpdata"
            size="small"
            @change="getdata"
          >
            <el-radio label="true" border>已上报</el-radio>
            <el-radio label="false" border>未上报</el-radio>
            <el-radio label="" border>全部</el-radio>
          </el-radio-group>
        </div>
        <div class="zahungtai">
          <span style="width: 150px"
            ><i class="iconfont icon-shenpi"></i>审核结果：</span
          >
          <el-radio-group
            v-model="listquery.isOk"
            size="small"
            @change="getdata"
          >
            <el-radio label="1" border>通过</el-radio>
            <el-radio label="-1" border>未通过</el-radio>
            <el-radio label="0" border>未审核</el-radio>
            <el-radio label="" border>全部</el-radio>
          </el-radio-group>
        </div>
      </div>
      <div class="zahungtai" style="margin-left: 20px; margin-top: 10px">
        <span style="width: 150px; margin-right: 40px"
          ><i class="icon iconfont icon-w_cunzhuang"></i>村庄名：</span
        >
        <el-input
          v-model="listquery.key"
          size="small"
          suffix-icon="el-icon-search"
          class="einput"
          style="width: 320px"
          clearable
          placeholder="请输入村庄名"
          @change="getdata"
          @clear="getdata"
        />
      </div>
    </div>

    <el-dialog
      title="指标成果上传"
      :visible.sync="dialogVisible"
      width="30%"
      append-to-body
      :before-close="beforeClose"
    >
      <el-upload
        ref="upload"
        class="upload-demo demo1"
        v-show="fileList.length == 0"
        action=""
        accept=".xls,.xlsx"
        :show-file-list="true"
        :limit="1"
        :file-list="fileList"
        :http-request="fileSubmit"
        :on-change="fileChange"
        :on-exceed="fileExceed"
        :on-remove="fileRemove"
      >
        <div class="wrap">
          <el-button size="small" type="primary">
            <i class="el-icon-plus"></i>选取文件</el-button
          >
          <div slot="tip" class="el-upload__tip tip1">仅支持Excel文档</div>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button @click="(dialogVisible = false), beforeClose()"
          >取 消</el-button
        >
        <el-button type="primary" @click="tijiao">提交</el-button>
      </span>
    </el-dialog>
    <div class="header"><i class="el-icon-d-arrow-right"></i>编制村庄列表</div>
    <el-table
      :data="tableData"
      stripe
      border
      style="width: 100%"
      class="eltable"
    > 
      <el-table-column prop="city" label="所属市" width="180" />
      <el-table-column prop="country" label="所属区县" width="180" />
      <el-table-column prop="town" label="所属乡镇" width="180" />
      <el-table-column prop="state" label="审核结果">
        <template slot-scope="scope">
          <span v-if="scope.row.state == true" style="color: green">通过</span>
          <span v-if="scope.row.state == false" style="color: green"
            >未通过</span
          >
          <span v-else>未审核</span>
        </template>
      </el-table-column>
      <el-table-column prop="village" label="村庄名" />
      <el-table-column prop="state" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.achievementsId">已上报</span>
          <span v-else>未上报</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="250" fixed="right">
        <template slot-scope="scope">
          <div v-if="scope.row.achievementsId">
            <el-button type="success" plain @click="approval(scope.row.id)"
              ><i class="icon iconfont icon-shangbao"></i>重新上传</el-button
            >
            <el-button type="primary" plain @click="queryrecord(scope.row)"
              ><i class="icon iconfont icon-jilu"></i>查看记录</el-button
            >
          </div>
          <div v-else>
            <el-button type="success" plain @click="approval(scope.row.id)"
              ><i class="icon iconfont icon-shangbao"></i>上传</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-if="tableData.length > 0"
      class="elpagi"
      :total="total"
      @size-change="getdata"
      @current-change="getdata"
      @prev-click="getdata"
      @next-click="getdata"
      :current-page.sync="listquery.currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="listquery.pageSize"
      layout="total,sizes, prev, pager, next, jumper"
    />
  </div>
</template>
<script>
import tableHeader from "../components/TableHeader";
import { achievementslist, updata } from "@/api/index.js";
export default {
  components: {
    tableHeader,
  },
  data() {
    return {
      listquery: {
        pageSize: 10,
        currentPage: 1,
        key: "",
        isOk: "",
        isUpdata: "",
      },
      isloading: false,
      total: 0,
      dialogVisible: false,
      fileList: [],
      tableData: [],
      files: [],
      id: "",
    };
  },
  mounted() {
    this.getdata();
  },
  methods: {
    async getdata() {
      this.isloading = true;
      let res = await achievementslist(this.listquery);
      this.tableData = res.data.content;
      this.total = res.data.totalElements;
      this.isloading = false;
    },

    approval(id) {
      this.dialogVisible = true;
      this.id = id;
    },
    beforeClose(done) {
      this.files = [];
      this.fileList = [];
      if (done) done();
    },
    fileSubmit(data) {
      this.files.push(data.file);
    },

    fileRemove(file, fileList) {
      this.files = [];
    },
    fileChange() {},
    fileExceed() {
      this.$message.warning(`每次只能上传1个文件`);
    },
    queryrecord(row) {
      this.$store.dispatch("setRowCache", row);
      this.$router.push("/approval");
    },
    tijiao() {
      if (this.files.length == 0) {
        this.$notify.error({
          title: "错误",
          message: "请上传指标成果",
        });
      } else {
        let id = this.id;
        let data = new FormData();
        data.append("id", id);
        data.append("file", this.files[0]);
        updata(data)
          .then((res) => {
            if (res.success) {
              this.$message({
                message: "上报成功",
                type: "success",
              });
              this.dialogVisible = false;
              this.beforeClose();
              this.getdata();
            } else {
              this.$notify.error({
                title: "上报失败",
                message: res.message,
              });
            }
          })
          .catch((err) => {
            this.$notify.error({
              title: "失败",
              message: "服务忙，请稍后再试",
            });
          });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../../../public/css/table.scss";
.zhibiaocontainer {
   margin: 5px;
  padding-bottom: 10px;
  overflow-y: auto;
  position: relative;
  height: 100%;
}
::v-deep .el-dialog__body {
  padding: 0 20px 10px 20px;
}
::v-deep .el-upload {
  position: relative;
  width: 100%;
}
.wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.over-header {
  background-color: #fff;
  border-radius: 5px;
  margin-bottom: 15px;
  padding-bottom: 15px;

  .header {
    border-bottom: 1px dashed #ccc;
  }

  .search {
    padding: 10px 20px;
    justify-content: space-between;
  }

  .zahungtai {
    display: flex;
    align-items: center;
    i {
      font-size: 18px;
      margin-right: 5px;
      color: #4cc8c7;
    }
  }
}
.header {
  font-size: 14px;
  font-weight: 600;
  line-height: 35px;
  margin-right: 5px;
  border-bottom: 1px dashed #ccc;

  i {
    color: #4778c7;
  }
}
.tip1 {
  margin-top: 0;
  line-height: 22px;
  color: red;
}
</style> 
